local skel = fk.CreateSkill{--定义
  name = "knu__zongxian",
}

local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{--翻译
  ["knu__zongxian"] = "宗燹",
  [":knu__zongxian"] = "你造成或受到过伤害的阶段结束时，你可以将两张手牌当【借刀杀人】使用；然后若没有基本牌进入弃牌堆，目标角色重复此流程。",
  
  ["#knu__zongxian_ask"] = "宗燹：你可以将两张手牌当【借刀杀人】使用；然后若没有基本牌进入弃牌堆，目标角色重复此流程",
  ["#knu__zongxian2_ask"] = "将两张手牌当【借刀杀人】使用；然后若没有基本牌进入弃牌堆，目标角色重复此流程",

  ["$knu__zongxian1"] = "驱龙造燹，斗祸为宗。",
  ["$knu__zongxian2"] = "薪火相传，该到你了。",
}

skel:addAcquireEffect(function (self, player, is_start)--DIYU的中央区加入游戏
  player.room:addSkill("#CenterArea")
end)

skel:addEffect(fk.EventPhaseEnd, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and
      #player.room.logic:getActualDamageEvents(1, function(e)
        return e.data.to == player or e.data.from == player
      end,Player.HistoryPhase) > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local use = room:askToUseVirtualCard(player, {
      name = "klee__collateral",
      skill_name = skel.name,
      prompt = "#knu__zongxian_ask",
      cancelable = true,
      card_filter = {
        n = 2,
        cards = player:getHandlyIds()
      },
      skip = true,
    })
    if use then
      event:setCostData(self, {extra_data = use})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = event:getCostData(self).extra_data
    local to
    local cardsa
    local cardsb
    if use then
      cardsa = table.filter(DIY.getCenterCards(room),function (c) return Fk:getCardById(c).type == Card.TypeBasic end)
      to = use.tos[1]
      room:useCard(use)--用牌
      room:cleanProcessingArea()--清理中央区的牌，以方便下面处理基本牌进弃牌堆
      cardsb = table.filter(DIY.getCenterCards(room),function (c) return Fk:getCardById(c).type == Card.TypeBasic end)
      ---
      while #cardsa == #cardsb do
        cardsa = table.filter(DIY.getCenterCards(room),function (c) return Fk:getCardById(c).type == Card.TypeBasic end)
        if to.dead or #to:getCardIds(Player.Hand) < 1 then return end
        use = room:askToUseVirtualCard(to, {
          name = "klee__collateral",
          skill_name = skel.name,
          prompt = "#knu__zongxian2_ask",
          cancelable = false,
          card_filter = {
          n = 2,
          cards = to:getHandlyIds()
          },
        })
        if use then
          to = use.tos[1]
          room:cleanProcessingArea()
          cardsb = table.filter(DIY.getCenterCards(room),function (c) return Fk:getCardById(c).type == Card.TypeBasic end)
        else
          break
        end
      end
      ---
    end
  end,
})


return skel